/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dbdir.core.datastore.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.dbdir.core.Logger;

/**
 *
 * @author thotheolh
 */
public class DBManager {

    private String dbConnPath = null;
    private String dbUsername = null;
    private String dbPassword = null;
    private Logger logger = new Logger();

    public DBManager(String connPath, String username, String password) {
        this.setDbConnPath(connPath);
        this.setDbUsername(username);
        this.setDbPassword(password);
    }

    public Connection getConnection() {
        Connection connection = null;
        try {
            Class.forName("org.h2.Driver").newInstance();
            connection = DriverManager.getConnection(this.getDbConnPath(), this.getDbUsername(), this.getDbPassword());
        } catch (SQLException ex) {
            logger.log(3, ex.getMessage());
        } catch (ClassNotFoundException ex) {
            logger.log(3, ex.getMessage());
        } catch (InstantiationException ex) {
            logger.log(3, ex.getMessage());
        } catch (IllegalAccessException ex) {
            logger.log(3, ex.getMessage());
        }
        return connection;
    }

    /**
     * @return the dbConnPath
     */
    public String getDbConnPath() {
        return dbConnPath;
    }

    /**
     * @param dbConnPath the dbConnPath to set
     */
    public void setDbConnPath(String dbConnPath) {
        this.dbConnPath = dbConnPath;
    }

    /**
     * @return the dbUsername
     */
    public String getDbUsername() {
        return dbUsername;
    }

    /**
     * @param dbUsername the dbUsername to set
     */
    public void setDbUsername(String dbUsername) {
        this.dbUsername = dbUsername;
    }

    /**
     * @return the dbPassword
     */
    public String getDbPassword() {
        return dbPassword;
    }

    /**
     * @param dbPassword the dbPassword to set
     */
    public void setDbPassword(String dbPassword) {
        this.dbPassword = dbPassword;
    }
}
